<?php if ( ! defined('BASEPATH')) exit('No direct script access allowed');
class generate extends MX_Controller
{
    public function generate()
    {
        parent::__construct();
        $this->load->helper('file');    
    }
    public function index()
    {
        $this->load->view('main');
    }
    public function getInfo()
    {
        $table = $_POST['title'];
        $fields = $this->db->list_fields($table);
        $data = array('fields' => $fields, 'table' => $table);
        $this->load->view('gene2', $data);
    }
    
    private function getData()
    {
        $_SESSION['gene']['fk'] = $_POST['txt_fore'];
        $_SESSION['gene']['table'] = $_POST['title'];
        $_SESSION['gene']['arrDis'] = $_POST['arrDisplay'];
        $_SESSION['gene']['strDis'] = implode(', ', $_POST['arrDisplay']);
        //$_SESSION['gene']['fielsList'] = $_POST['sAction']; //$this->db->list_fields($_POST['title']);
        
        $arrAction = $_POST['arrAction'];
        $arrsAction = $_POST['sAction'];
        $arrXAction = array();
        $arrKAction = array();
        $i = 0;
        foreach ($arrsAction as $key => $val) {
            if ($val != 'none') {
                $arrXAction[$arrAction[$i]] = $val;
                $arrKAction[$i] = $arrAction[$i];
                $i++;
            }
        }
        $_SESSION['gene']['arrAction'] = $arrXAction;
        $_SESSION['gene']['strAction'] = implode(', ', $arrXAction);
        $_SESSION['gene']['keyAction'] = $arrKAction;
    
        
        $_SESSION['gene']['pk'] = $_POST['arrPK'];
       
    }
     
    public function dis()
    {
        if (isset($_SESSION['gene'])) unset($_SESSION['gene']);
        $this->getData();
        
        $this->load->model('generate_model');
        $this->load->model('generate_control');
        $this->load->model('generate_view');
        
        
        $this->generate_model->main();
        $this->generate_control->main();
        $this->generate_view->main();
        $this->generate_view->add();
        $this->generate_view->edit();
    }
        
}
